//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.qy137.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy137.entity.Link;
import com.qy137.vo.LinkVo;
import java.time.LocalDateTime;
import org.apache.commons.lang.StringUtils;
import org.qy137.dao.LinkDao;
import org.qy137.service.LinkService;
import org.qy137.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LinkServiceImpl implements LinkService {
    @Autowired
    private LinkDao linkDao;

    public LinkServiceImpl() {
    }

    public CommonResult getAllLink(Integer page, Integer limit, LinkVo linkVo) {
        Page<Link> linkPage = new Page((long)page, (long)limit);
        QueryWrapper<Link> wrapper = new QueryWrapper();
        wrapper.eq("is_deleted", 0);
        if (StringUtils.isNotEmpty(linkVo.getLinkName())) {
            wrapper.like("link_name", linkVo.getLinkName());
        }

        if (linkVo.getIsDisable() != null) {
            wrapper.eq("is_disable", linkVo.getIsDisable());
        }

        Page<Link> linkPage1 = (Page)this.linkDao.selectPage(linkPage, wrapper);
        return linkPage1.getRecords().size() > 0 ? new CommonResult(2000, "查询成功", linkPage1) : new CommonResult(5000, "查询失败", (Object)null);
    }

    public CommonResult changeStatus(String linkId, Integer isDisable) {
        Link link = new Link();
        link.setLinkId(linkId);
        link.setIsDisable(isDisable);
        int i = this.linkDao.updateById(link);
        return i > 0 ? new CommonResult(2000, "修改成功", (Object)null) : new CommonResult(5000, "修改失败", (Object)null);
    }

    public CommonResult deleteLink(String linkId) {
        Link link = new Link();
        link.setLinkId(linkId);
        link.setIsDeleted(1);
        int i = this.linkDao.updateById(link);
        return i > 0 ? new CommonResult(2000, "删除成功", (Object)null) : new CommonResult(5000, "删除失败", (Object)null);
    }

    public CommonResult updateOrAddLink(LinkVo linkVo) {
        Link link;
        int insert;
        if (StringUtils.isNotEmpty(linkVo.getLinkId())) {
            link = new Link();
            link.setLinkId(linkVo.getLinkId());
            link.setGmtModified(LocalDateTime.now());
            link.setLinkName(linkVo.getLinkName());
            link.setLinkUrl(linkVo.getLinkUrl());
            insert = this.linkDao.updateById(link);
            return insert > 0 ? new CommonResult(2000, "修改成功", (Object)null) : new CommonResult(5000, "修改失败", (Object)null);
        } else {
            link = new Link();
            link.setLinkName(linkVo.getLinkName());
            link.setLinkUrl(linkVo.getLinkUrl());
            link.setIsDeleted(0);
            link.setIsDisable(0);
            insert = this.linkDao.insert(link);
            return insert > 0 ? new CommonResult(2000, "添加成功", (Object)null) : new CommonResult(5000, "添加失败", (Object)null);
        }
    }
}
